Skip to content

fix: include accumulated reasoning_details in reasoning-end event + regression test#395

Merged
robert-j-y merged 6 commits intomainfrom
pr-394-review
Feb 9, 2026
Merged

fix: include accumulated reasoning_details in reasoning-end event + regression test#395
robert-j-y merged 6 commits intomainfrom
pr-394-review

Conversation

@robert-j-y
Copy link
Contributor

Description

Incorporates the fix from PR #394 (by @kalaomer) with formatting fixes, a patch changeset, and an e2e/issues/ regression test.

Bug: When streaming a text-only response (no tool calls) with reasoning enabled, the reasoning-end stream event was emitted without providerMetadata. The Anthropic signature arrives in the last reasoning delta, but reasoning-end didn't carry it forward. The AI SDK uses reasoning-end's providerMetadata to update the reasoning part, so the signature was lost — causing "Invalid signature in thinking block" on subsequent turns.

This was not an issue for tool-call responses, where accumulatedReasoningDetails were already attached to the first tool-call event.

Fix: Attach accumulatedReasoningDetails to reasoning-end's providerMetadata in both emission points:

  1. When text content starts (reasoning ends before text begins)
  2. In flush (reasoning ends when stream completes)

Before:

// reasoning-end emitted without providerMetadata → signature lost
controller.enqueue({ type: 'reasoning-end', id: reasoningId || generateId() });

After:

// reasoning-end now carries accumulated reasoning_details (including signature)
controller.enqueue({
  type: 'reasoning-end',
  id: reasoningId || generateId(),
  providerMetadata: accumulatedReasoningDetails.length > 0
    ? { openrouter: { reasoning_details: accumulatedReasoningDetails } }
    : undefined,
});

Important review notes

  • Core fix authored by @kalaomer in fix: include accumulated reasoning_details in reasoning-end event #394 — this branch adds formatting fixes, changeset, and regression test on top
  • E2e test was NOT run against live API — only unit tests were verified locally (210/210 pass on both node + edge). The e2e test targets anthropic/claude-sonnet-4 and will need a live run to confirm
  • Second e2e test silently passes if content is a string — the if (typeof content === 'string') return; guard at line 106 means the multi-turn test won't assert anything if the AI SDK returns string content instead of structured parts

Checklist

  • I have run pnpm stylecheck and pnpm typecheck
  • I have run pnpm test and all tests pass
  • I have added tests for my changes (if applicable)
  • I have updated documentation (if applicable) — N/A, no doc changes needed

Changeset

  • I have run pnpm changeset to create a changeset file

Link to Devin run | Requested by @robert-j-y

kalaomer and others added 6 commits February 8, 2026 09:48
…g-end event

The reasoning-start event only carries the first streaming delta's
providerMetadata, but Anthropic signatures arrive in the last delta.
The AI SDK updates the reasoning part's providerMetadata from the
reasoning-end event. Without this fix, text-only responses (no tool
calls) lose the signature, causing "Invalid signature in thinking
block" errors on subsequent turns in multi-turn conversations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
@robert-j-y robert-j-y merged commit 23f02f1 into main Feb 9, 2026
2 checks passed
@robert-j-y robert-j-y deleted the pr-394-review branch February 9, 2026 20:38
@github-actions github-actions bot mentioned this pull request Feb 9, 2026
kesavan-byte pushed a commit to osm-API/ai-sdk-provider that referenced this pull request Feb 13, 2026
…egression test (OpenRouterTeam#395)

* fix: include accumulated reasoning_details with signature in reasoning-end event

The reasoning-start event only carries the first streaming delta's
providerMetadata, but Anthropic signatures arrive in the last delta.
The AI SDK updates the reasoning part's providerMetadata from the
reasoning-end event. Without this fix, text-only responses (no tool
calls) lose the signature, causing "Invalid signature in thinking
block" errors on subsequent turns in multi-turn conversations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* style: fix formatting in test file

Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>

* test: add e2e regression test for issue OpenRouterTeam#394 reasoning-end signature

Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>

* chore: add patch changeset for reasoning-end signature fix

Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>

* style: fix formatting in regression test

Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>

* style: fix formatting in regression test

Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>

---------

Co-authored-by: Ömer Kala <kalamustafa@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants